import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.*;

public class RunCallable {
    public static void main(String[] args) {
        ExecutorService pool = new ThreadPoolExecutor(3,8,2000, TimeUnit.MILLISECONDS,new LinkedBlockingQueue<>(5));
        List<Future<String>> results = new ArrayList<>();
        for(int i=0;i<20;i++){
            Future<String> f = pool.submit(new MyTask(i));
            results.add(f);
            System.out.println("任务"+i+"完成");
        }
        pool.shutdown();
        for(Future<String> f : results){
            try{
                System.out.println(f.get());
            } catch (ExecutionException | InterruptedException e) {
                e.printStackTrace();
            }
        }
    }
}
